# # server.py
import os

from csv_agent.agent_retrieval import prompt, agent_executor

# os.environ["OPENAI_API_KEY"] = "sk-qSEb3B8xc7Hsep75F95c54968a344a208aE15a2b198d0e74"
os.environ["OPENAI_API_KEY"] = "sk-MbqRvQXUjoIol65lC09cCe135c274e72AbC0B327Cd3c3990"

from fastapi import FastAPI, Depends
from fastapi.responses import RedirectResponse
from langserve import add_routes
from csv_agent.agent_retrieval import agent_executor as csv_agent_chain
from core.database import engine
from core.models import Base
from core.dependencies import common_dependencies
from routers import user, conversation, messages

# 创建数据库表
Base.metadata.create_all(bind=engine)

app = FastAPI()


@app.get("/")
async def redirect_root_to_docs():
    return RedirectResponse("/csv-agent/playground")


add_routes(app, csv_agent_chain, path="/csv-agent")
# add_routes(app, csv_agent_chain, path="/csv-agent", dependencies=[Depends(common_dependencies)])

app.include_router(user.router)
app.include_router(conversation.router)
app.include_router(messages.router)

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="localhost", port=8000)